class TreeNode(object):
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right


class FindElements(object):

    def __init__(self, root):
        """
        :type root: TreeNode
        """
        self.root = root

        def search(node, val):
            node.val = val
            if node.left:
                search(node.left, 2 * val + 1)
            if node.right:
                search(node.right, 2 * val + 2)

        search(self.root, 0)

    def find(self, target):
        """
        :type target: int
        :rtype: bool
        """
        out = [target]
        while target > 0:
            target = (target - 1) // 2
            out.append(target)
        out.reverse()
        node = self.root
        for num in out[1:]:
            if num % 2 == 1:
                if node.left:
                    node = node.left
                else:
                    return False
            else:
                if node.right:
                    node = node.right
                else:
                    return False
        return True
